<template>
    <div>
        <div class="qj">请输入请假原因</div>
        <textarea  v-model="content" name="" id="" cols="80" rows="20"></textarea>
        <el-row>
            <el-button  type="primary" plain>{{status}}</el-button>
            <el-button type="success" @click="addContent" plain>提交</el-button>
        </el-row>
    </div>
</template>

<script>
    name:"askForLeaveList"
    export default {
        data(){
            return {
                content:'',
                status:'状态'
            }
        },
        async mounted(){
            // console.log(111,this.$store.state.askForLeave.content)
           await this.$store.dispatch("getAddContent",{pageIndex:1})
            for(let key in this.$store.state.askForLeave.content){
                // console.log(this.$store.state.askForLeave.content[key])
                if(this.$store.state.askForLeave.content[key].name===localStorage.adminName){
                        if(this.$store.state.askForLeave.content[key].status===1){
                            this.status="请求中"
                        }
                        if(this.$store.state.askForLeave.content[key].status===0) this.status="未批准" 
                        if(this.$store.state.askForLeave.content[key].status===2) this.status="已批准"
                }
            }
        },
        updated(){
            //  console.log(this.content)
        },
        methods:{
            async addContent(){
                // console.log(this.content)
               if(this.content){
                //    this.status="等待中"
                   await this.$store.dispatch("addContent",{
                       content:this.content,
                       name:localStorage.adminName,
                       status:1//状态的默认值是未同意
                       })
                //    console.log(222)
                   this.$message({
                    message: '提交成功',
                    type: 'success'
                    });
                    this.content=''
               }else{
                   this.$message.error('请输入请假信息');
               }
               
            }
        }
    }
</script>

<style lang="less" scoped>
    .qj{
        width: 100%;
        font-size: 40px;
        line-height: 70px;
    }
    .el-row{
        .el-button--success{
            margin-left:450px; 
        }
    }
</style>